package zrar.util;

import java.util.ArrayList;
import java.util.List;

import zrar.entity.AnswerPeople;
import zrar.entity.Prize;

public class ToolUtil {

	static List<Integer> intRandomList=new ArrayList<Integer>();
	
	public static void main(String[] args) {
		List<String> lit = new ArrayList<String>();
		
		lit.add("aaa");
		lit.add("bbb");
		lit.add("ccc");
		lit.add("ddd");
		
		System.out.println(lit.indexOf("ccc"));
		
	}
	
	public static void printList(List<Integer> lis) {
		for(int i=0;i<lis.size();i++){
			System.out.print(lis.get(i)+",");
		}
		System.out.println("");
	}

	/**
	 * 产生一组随机数
	 * @param size 数组长度
	 * @param scope 取值范围
	 * @return
	 */
	public static List<Integer> randomNums(int size,int scope){
		
		
		intRandomList.clear();
		for(int i=0;i<size;i++){
			
			while(true){
				int temp= (int) (Math.random()*scope);
				if(isNotRepeat(intRandomList,temp)){
					intRandomList.add(temp);
					break;
				}
			}
		}
		
		return intRandomList;
	}

	private static boolean isNotRepeat(List<Integer> intList, int temp) {		
		for(int i=0;i<intList.size();i++){
			if(temp==intList.get(i)){				
				return false;
			}
		}
		return true;
	}
	
	/**
	 * 隐藏用户手机号
	 * @param pp
	 * @return
	 */
	public static String hideTelNum(String telphone){
		String discon="";
		
		String head=telphone.substring(0, 3);
		String tail= telphone.substring(7,telphone.length());		
		discon=head+"****"+tail;
				
		return discon;
	}
	
	/**
	 * 显示用户地址 只显示到地级市
	 * @param address
	 * @return
	 */
	public static String hideAddress(String address){
		String hideaddr="";	
		if(address.contains("市")){
			hideaddr = address.substring(0, address.indexOf("市")+1);
		}else if(address.contains("州")){
			hideaddr = address.substring(0, address.indexOf("州")+1);
		}else if(address.contains("镇")){
			hideaddr = address.substring(0, address.indexOf("镇")+1);
		}else{
			hideaddr = address.substring(0, address.length());
		}
				
		return hideaddr;
	}
	
	/**
	 * 获取当前要 抽的奖项
	 * @param prize
	 * @return
	 */
	public static int getRealFetchNum(Prize prize){
		int realFetchNum=0;
		int temp =prize.getTotal()-prize.getPersons().size();
		if(temp>=prize.getFetchnum()){			
			realFetchNum = prize.getFetchnum();
		}else{
			realFetchNum = temp;
		}
		return realFetchNum;
	}
	
	/**
	 * 抽到第几步了
	 * @param prize
	 * @return
	 */
	public static int getFetchStep(Prize prize){
		int size = prize.getPersons().size();
		int fetch = prize.getFetchnum();
		int step = 1;
		if(size==0){
			step = 1;
		}else if(size==prize.getTotal()){
			step = (int) Math.ceil((double)size/fetch);
		}else{
			step = ((int)(size/fetch))+1;
		}
		return step;
	}
	
	public static String[] splitInfo(String info){
		
		int index =info.indexOf(",");
		
		String str1=info.substring(0, index)+")";
		String str2 =info.substring(index+1,info.length()-1);
		
		String spilt[] ={str1,str2};
		
		return spilt;
	}
	
	//截取名字
	public static String cutUpLongName(String pname){
		String head="";
		String tail="";
		head=pname.substring(0, 3);
		tail=pname.substring(pname.length()-2, pname.length());
		
		return head+".."+tail;
	}

}
